var express = require('express');
var router = express.Router();
var User = require('../../../../models/user.ts');
var fs = require('fs');
const BASEURL = 'rests/business/store-shop/';

/**根据id查找用户信息。
 * 入参
 * @param id 客户id
 */
//@Api(name="/rest/store/shop/layout")
router.get('/store/shop/layout', (req, res) => {
  try {
    let fileUrl = BASEURL + 'layout.json';
    if (fs.existsSync(fileUrl)) {
      let response = fs.readFileSync(fileUrl, 'utf8');
      let superHeroes = JSON.parse(response);
      res.send(superHeroes);
    } else {
      res.send('文件不存在');
    }
  } catch (error) {
    res.send(error);
  }
});

// 定义 POST 接口
//@Api(name="/rest/store/shop/data")
router.post('/store/shop/data', (req, res) => {
  try {
    let fileUrl = BASEURL + 'data.json';
    if (fs.existsSync(fileUrl)) {
      let response = fs.readFileSync(fileUrl, 'utf8');
      let superHeroes = JSON.parse(response);
      res.send(superHeroes);
    } else {
      res.send('文件不存在');
    }
  } catch (error) {
    res.send(error);
  }
});

module.exports = router;
